package com.tencent.iov.cowin.befsale.clue.value.utils;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.tencent.iov.cowin.befsale.clue.value.enums.ClueStatsEnum;

import java.util.stream.Stream;

/**
 * @Author xiamu
 * @Date 2022/1/26 13:27
 * @Version 1.0
 **/
public class ClueStatusConverterUtils implements Converter<Integer> {
    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty,
                                    GlobalConfiguration globalConfiguration) {
        return Stream.of(ClueStatsEnum.values()).filter(enums -> enums.getName().equals(cellData.getStringValue())).findAny()
                .map(ClueStatsEnum::getCode).orElse(null);
    }

    @Override
    public CellData convertToExcelData(Integer code, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return Stream.of(ClueStatsEnum.values()).filter(enums -> enums.getCode() == code.intValue()).findAny()
                .map(s -> new CellData(s.getName())).orElse(null);
    }
}
